﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    class DB
    {


        public static SqlSugarClient Client
        {
            get
            {

                string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = conn, DbType = DbType.MySql, IsAutoCloseConnection = true });
                db.Ado.IsEnableLogEvent = true;
                db.Ado.LogEventStarting = (sql, pars) =>
                {
                    Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                    Console.WriteLine();
                };

                return db;
            }

        }
    }
}
